using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.ComponentModel;

namespace QiHe.ReliableData
{
    public class DataType
    {
        private string name;

        [XmlAttribute]
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private List<TypeField> fields = new List<TypeField>();

        [Browsable(false)]
        [XmlElement("TypeField")]
        public List<TypeField> Fields
        {
            get { return fields; }
            set { fields = value; }
        }

        public DataType() { }

        public DataType(string name)
        {
            Name = name;
        }

        public override string ToString()
        {
            return Name;
        }

        public TypeField GetTypeField(string name)
        {
            return Fields.Find(
                delegate(TypeField field)
                {
                    return field.Name == name;
                });
        }
    }

    public class TypeField
    {
        //public string FieldName;
        //public string FieldType;
        //public string XmlSerialize;
        //public string Category;
        //public string Description;


        private string name;

        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                if (name != value)
                {
                    name = value;
                }
            }
        }

        private string fieldtype;

        [TypeConverter(typeof(FieldTypeConverter))]
        public string FieldType
        {
            get
            {
                return fieldtype;
            }
            set
            {
                if (fieldtype != value)
                {
                    fieldtype = value;
                }
            }
        }

        private string xmlserialize;

        [TypeConverter(typeof(XmlSerializeConverter))]
        public string XmlSerialize
        {
            get
            {
                return xmlserialize;
            }
            set
            {
                if (xmlserialize != value)
                {
                    xmlserialize = value;
                }
            }
        }

        private string valueSet;

        public string ValueSet
        {
            get
            {
                return valueSet;
            }
            set
            {
                if (valueSet != value)
                {
                    valueSet = value;
                }
            }
        }

        private string category;

        public string Category
        {
            get
            {
                return category;
            }
            set
            {
                if (category != value)
                {
                    category = value;
                }
            }
        }

        private string description;

        public string Description
        {
            get
            {
                return description;
            }
            set
            {
                if (description != value)
                {
                    description = value;
                }
            }
        }

    }
}
